package com.obrock;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * Created with IntelliJ IDEA.
 * User: Дмитрий Г. Кузнецов
 * Date: 17.10.12
 * Time: 13:15
 * To change this template use File | Settings | File Templates.
 */
public class ViewHeader extends LinearLayout {

    public TextView accountTitle;
    public TextView accountBalance;
    public TextView accountDetails;
    public ImageView accountIcon;
    public ImageView actionIcon;
    public ImageView syncIcon;
    public TextView amountBalance;
    public TextView amountDebt;
    public TextView amountNormal;

    public LinearLayout blockLines;
    public LinearLayout blockColumns;

    public ViewHeader(Context context) {
        super(context);
        init(context);
    }

    public ViewHeader(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    void init(Context context) {
        inflate(context, R.layout.header, this);

        accountTitle = (TextView) findViewById(R.id.account_title);
        accountBalance = (TextView) findViewById(R.id.account_amount);
        accountDetails = (TextView) findViewById(R.id.account_debt);
        accountIcon = (ImageView) findViewById(R.id.icon);
        actionIcon = (ImageView) findViewById(R.id.action);
        syncIcon = (ImageView) findViewById(R.id.sync);
        amountBalance = (TextView) findViewById(R.id.amount_balance);
        amountDebt = (TextView) findViewById(R.id.amount_debt);
        amountNormal = (TextView) findViewById(R.id.amount_normal);

        blockLines = (LinearLayout) findViewById(R.id.block_lines);
        blockColumns = (LinearLayout) findViewById(R.id.block_columns);
    }

    public void set(Drawable icon, Drawable action, String title) {
        blockColumns.setVisibility(GONE);
        blockLines.setVisibility(VISIBLE);

        accountBalance.setText("   ");
        accountDetails.setText("   ");

        accountTitle.setText(title);
        accountIcon.setImageDrawable(icon);
        actionIcon.setImageDrawable(action);
    }

    public void set(Drawable icon, Drawable action, String title, String subtitle) {
        blockLines.setVisibility(VISIBLE);
        blockColumns.setVisibility(GONE);

        accountTitle.setText(title);
        accountIcon.setImageDrawable(icon);
        accountBalance.setText(subtitle);
        accountDetails.setVisibility(GONE);
        actionIcon.setImageDrawable(action);
    }

    public void set(Drawable icon, Drawable action, String title, String subtitle, String remark) {
        blockLines.setVisibility(VISIBLE);
        blockColumns.setVisibility(GONE);

        accountTitle.setText(title);
        accountIcon.setImageDrawable(icon);
        accountBalance.setText(subtitle);
        accountDetails.setText(remark);
        actionIcon.setImageDrawable(action);
    }


    public void set(Drawable icon, Drawable action, String title, double balance, double debt, double normal) {
        blockLines.setVisibility(GONE);
        blockColumns.setVisibility(VISIBLE);

        accountTitle.setText(title);
        accountIcon.setImageDrawable(icon);
        amountBalance.setText(String.format("%.2f", balance));
        amountDebt.setText(String.format("%.2f", debt));
        amountNormal.setText(String.format("%.2f", normal));
        actionIcon.setImageDrawable(action);
    }

}
